#include "stdafx.h"
#include "ProceduralSystem/ProceduralProductionRuleBase.h"

void CProceduralProductionRuleBase::CalcSize()
{
}

void CProceduralProductionRuleBase::GenerateFloor(TModulesList &modulesList)
{
	assert(0);
}

CProceduralModule* CProceduralProductionRuleBase::GenerateModule(int nX,int nY)
{
	return NULL;
}

bool CProceduralProductionRuleBase::IsModuleInModulesList(TModulesList &searchList, CProceduralModule &module)
{
	TModulesListIt sIter = searchList.begin();
	for ( ; sIter!= searchList.end(); ++sIter)
	{
		CProceduralModule *searchModule = &(*sIter);
		if (!searchModule->m_pObject) 
			continue;
		if (!module.m_pObject) 
			continue;

		AABB bbox1=searchModule->m_bbox;
		AABB bbox2=module.m_bbox;

		float fDist2=bbox1.GetCenter().GetSquaredDistance(bbox2.GetCenter());
		if (fDist2<MAX_BBOX_SPACE)
			return true;
	}

	return false;
}

CProceduralModule& CProceduralProductionRuleBase::SpawnModule(CProceduralModule &sourceModule, CProceduralModule &newModule, const Vec3 &newModulePosition)
{
	CBrushObject *newLinkedObj = (CBrushObject*)GetIEditor()->NewObject(BRUSH_CLASS_NAME,sourceModule.m_pObject->GetGeometryFile());
	
	newLinkedObj->SetUniqName(sourceModule.m_pObject->GetName()+"-recreated");
	newLinkedObj->SetPos(newModulePosition);						
	newLinkedObj->SetRotation(sourceModule.m_pObject->GetRotation());
	newLinkedObj->SetScale(sourceModule.m_pObject->GetScale());

	newModule.Set(newLinkedObj);

	CProceduralProductionUtils procUtils;
	procUtils.CopyModule(sourceModule,newModule,false);

	return newModule;
}
